package game.web.struts.json;

import game.web.base.Constants;
import game.web.base.User;
import game.web.controller.WithdrawListControllor;
import game.web.dao.dto.WithdrawDTO;
import game.web.struts.WithdrawForm;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONObject;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import projectx.web.base.ConstantsProjectX;
import projectx.web.base.ProjectXSecurityAction;
import projectx.web.base.ProjectXForm;
import projectx.web.base.UserContext;
import projectx.web.base.navi.Function;

public class WithdrawListAction extends ProjectXSecurityAction {
	List<WithdrawDTO> rows = new ArrayList();
	@Override
	protected ActionForward execute(User user, Function function,
			ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpSession session, HttpServletResponse response) throws Exception {
		debugBegin();

		UserContext uc = getUc();
		
		WithdrawListControllor.execute(getUc(), (ProjectXForm) form);
		// output
		debugEnd();

		rows = (List<WithdrawDTO>) getUcAttribute(Constants.WITHDRAW_LIST_CHARGE_TO_LIST);

		BaseJson<WithdrawDTO> json = new BaseJson<WithdrawDTO>();
		WithdrawForm inputForm = (WithdrawForm)form;
		json.setPage(inputForm.getPage());
		json.setRecords(rows==null?0:rows.size());
		json.setRows(rows);
		JSONObject object = JSONObject.fromObject(json);
		
		this.setJsonString(object.toString());
		
		request.setAttribute(ConstantsProjectX.JSONSTRING, this.getJsonString());
		
		return findForward(mapping, forwardSuccess);
	}

	@Override
	protected boolean isPostMethodOnly() {
		return false;
	}
	
}
